require('../less/my.less')
require("../fonts/iconfont.css")

require('weui') //引入样式
const weui = require('weui.js') //引入js
//获取 头像
const heading = document.querySelector(".heading")
//昵称
const nickname = document.querySelector(".nickname")
//签名
const sign = document.querySelector('.sign')

//退出登录
const logout = document.querySelector(".logout")

//运动时间
const yunfen = document.querySelector(".yunfen")
//运动千卡
const yunqian = document.querySelector(".yunqian")

//大于
const dayu = document.querySelector(".dayu")
document.ready(function () {

    utils.registers()
    //动态导航
    utils.showTabs('my')

    dayu.addEventListener("click", function () {
        location.href = "./sportdata.html"
    })





    //获取个人信息
    function xinxi() {
        //获取本地存储中的用户id
        const userId = localStorage.getItem("userId")




        // console.log(userId);
        //发请求
        $http.get(`/users/mysportsBadge?userId=${userId}`, function (xingcan) {
            /* console.log(xingcan); */
            if (xingcan.status === 0) {
                const xingcan2 = xingcan.data.user;
                // console.log(xingcan2);

                //时间千卡那些
                const xingcan3 = xingcan.data.sports;

                //保存个人本地存储中的
                localStorage.setItem("xingcan2", JSON.stringify(xingcan2))
                //时间千卡那些  以及渲染时间千卡
                localStorage.setItem("xingcan2", JSON.stringify(xingcan3))
                if (xingcan3.times) yunfen.textContent = xingcan3.times
                if (xingcan3.calorie) yunqian.textContent = xingcan3.calorie


                //渲染数据 昵称
                nickname.textContent = xingcan2.nickname
                //头像
                if (xingcan2.imgurl) heading.src = "http://139.9.177.51:8099" + xingcan2.imgurl
                //签名
                if (xingcan2.sign) sign.textContent = xingcan2.sign
            }

        })
    }
    xinxi()

    //退出登录 ,退出后干掉所有本地存档里的信息
    /* logout.addEventListener("click", function () {
        localStorage.clear()
        //跳转到登录页面哦
        location.href = "./password.html"
    }) */

    //请提示
    logout.addEventListener("click", function () {
        weui.confirm('是否确定退出登录', function () {
            localStorage.clear()
            //跳转到登录页面哦
            location.href = "./password.html"
        })
    })

    /* const mywode = document.querySelector(".mywode");
    mywode.addEventListener("click", function () {
        location.href = "./my.html"
    }) */
})